home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!rbdc!usenet
- From: marty1@rbdc.rbdc.com (Jumping Jack Flash)
- Newsgroups: comp.lang.c
- Subject: Re: Help with a very weird C problem
- Date: Wed, 10 Apr 1996 06:02:42 GMT
- Organization: Red Barn Data Center, Winston-Salem, NC.
- Message-ID: <316b4a54.48010904@199.171.83.2>
- References: <31620c87.184254741@199.171.83.2> <4k2tdl$ft4@preeda.internex.net.au> <828718259snz@genesis.demon.co.uk>
- NNTP-Posting-Host: rbdc8.rbdc.com
- X-Newsreader: Forte Agent .99d/32.168
-
- On Fri, 05 Apr 96 15:30:59 GMT, Lawrence Kirby
- <fred@genesis.demon.co.uk> wrote:
-
- -In article <4k2tdl$ft4@preeda.internex.net.au>
- - sultan@connexus.apana.org.au "Jon Hornstein" writes:
- -
- ->With the briefest of looks at the code this function
- ->
- ->
- ->>char *PkunzipDir(char *curdir,char *name2,char *file)
- ->>{
- ->>char pkunzip2[120] = "pkunzip ";
- ->>strcat(pkunzip2,curdir);
- ->>strcat(pkunzip2,name2);
- ->>strcat(pkunzip2," ");
- ->>strcat(pkunzip2,curdir);
- ->>strcat(pkunzip2,file);
- ->>return(pkunzip2);
- ->>}
- ->
- ->should read
- ->
- ->
- ->char *PkunzipDir(char *curdir,char *name2,char *file)
- ->{
- ->static char pkunzip2[120] = "pkunzip ";
- ->
- -> strcat(pkunzip2,curdir);
- -> strcat(pkunzip2,name2);
- -> strcat(pkunzip2," ");
- -> strcat(pkunzip2,curdir);
- -> strcat(pkunzip2,file);
- -> return(pkunzip2);
- ->}
- -
- -That would fail if you called PkunzipDir() more than once.
- -
- -Or you could write it more simply and clearly (and correctly) as:
- -
- -char *PkunzipDir(char *curdir,char *name2,char *file)
- -{
- - static char pkunzip2[120];
- -
- - sprintf(pkunzip2, "pkunzip %s%s %s%s", curdir, name2, curdir,
- file);
- -
- - return pkunzip2;
- -}
- -
- -sprintf is extremely useful for string handling.
- -
- -It is generally better to have the calling function pass a pointer to
- a
- -suitable buffer than to return a pointer to a static buffer.
- ------------------------------------------
- -Lawrence Kirby | fred@genesis.demon.co.uk
- -Wilts, England | 70734.126@compuserve.com
- ------------------------------------------
-
- Here's where I'm at so far. Good Bad or Ugly. But it works like
- I want it to and is easier to read.
-
- #include <stdlib.h>
- #include <conio.h>
- #include <iostream.h>
- #include <string.h>
- #include <dir.h>
- #include <process.h>
- #include <stdio.h>
- #include <errno.h>
- #define TRUE 1
- #define FALSE 0
-
- char *PkunzipDir(char *curdir,char *name2,char *file);
- char *Current_Directory(char *path);
- void PkunzipSearch(void);
-
- int main(int argc, char **argv)
- {
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char file[MAXFILE];
- char ext[MAXEXT];
- char curdir[MAXPATH];
- struct ffblk ffblk;
- int done, stat;
-
-
- clrscr();//Clears Screen
- PkunzipSearch();//Searches for pkunzip.exe file
- Current_Directory(curdir);//Gets Current Directory
-
- if(argc == 2)
- {
- done = findfirst(argv[1],&ffblk,0);
- }
- else
- {
- done = findfirst("*.zip",&ffblk,0);
- }
-
- if(done)
- {
- clrscr();
- cout << "No Zipped files in current Directory\n";
- }
- else//A2
- {
- while (!done)
- {
- fnsplit(ffblk.ff_name,drive,dir,file,ext);
- stat = mkdir(file);
- if (!stat)
- {
- cout << "\n" << "Directory " << file << "
- created\n";
- cout << "Unzipping Files into it\n";
-
- if(system(PkunzipDir(curdir,ffblk.ff_name,file)))
- {
- cout << "ERROR\n";
- exit(EXIT_FAILURE);
- }
- }
- else
- {
- clrscr();
- cout << "Unable to create directory " << file
- << "\n";
- cout << "For zipped file " << file << ext;
- }
- done = findnext(&ffblk);
- }//Ends While
- }//Ends Else A2
- cout <<"\n" << "This program is Freeware\n";
- cout << "Written by Marty A. Lineberry\n";
- cout << "Internet address marty1@rbdc.rbdc.com\n";
- cout << "End of Program\n";
- return 0;
- }
-
-
- //**********************************************************
- char *PkunzipDir(char *curdir,char *name2,char *file)
- {
- static char pkunzip2[120]; //Keeps in mem
- pkunzip2[0] = '\0'; //Sets array to 0 bytes
- strcat(pkunzip2,"pkunzip ");
- strcat(pkunzip2,curdir);
- strcat(pkunzip2,name2);
- strcat(pkunzip2," ");
- strcat(pkunzip2,curdir);
- strcat(pkunzip2,file);
- return(pkunzip2);
- }
-
- //**********************************************************
- //* Used to get the current Drive & Directory *
- //**********************************************************
- char *Current_Directory(char *path)
- {
- strcpy(path, "X:\\"); /* fill string with form of response:
- X:\ */
- path[0] = 'A' + getdisk(); /* replace X with current drive
- letter */
- getcurdir(0, path+3); /* fill rest of string with current
- directory */
- if(strlen(path) > 3) /* Puts ending / if not root directory */
- {
- strcat(path,"\\");
- }
- return(path);
- }
-
-
- //*************************************************************
- void PkunzipSearch(void)
- {
- char *pkunzip_search;
- //Searches all current dos paths for pkunzip
- pkunzip_search = searchpath("pkunzip.exe");
- if(pkunzip_search == NULL)
- {
- clrscr();
- cout << "PKUNZIP.EXE must be in your path!";
- exit(EXIT_FAILURE);
- }
- return;
- }
-
-